#******************************************************************************
#
# Makefile - Rules for building the driver library.
#
# Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.
#
# Software License Agreement
#
# Luminary Micro, Inc. (LMI) is supplying this software for use solely and
# exclusively on LMI's Stellaris Family of microcontroller products.
#
# The software is owned by LMI and/or its suppliers, and is protected under
# applicable copyright laws.  All rights are reserved.  Any use in violation
# of the foregoing restrictions may subject the user to criminal sanctions
# under applicable laws, as well as to civil liability for the breach of the
# terms and conditions of this license.
#
# THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
# OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
# LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
# CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
#
# This is part of revision 920 of the Stellaris Driver Library.
#
#******************************************************************************

#
# Include the common make definitions.
#
include ../makedefs

#
# The list of objects to be included in the library.
#
OBJS=${COMPILER}/adc.o       \
     ${COMPILER}/comp.o      \
     ${COMPILER}/cpu.o       \
     ${COMPILER}/flash.o     \
     ${COMPILER}/gpio.o      \
     ${COMPILER}/i2c.o       \
     ${COMPILER}/interrupt.o \
     ${COMPILER}/pwm.o       \
     ${COMPILER}/qei.o       \
     ${COMPILER}/ssi.o       \
     ${COMPILER}/sysctl.o    \
     ${COMPILER}/systick.o   \
     ${COMPILER}/timer.o     \
     ${COMPILER}/uart.o      \
     ${COMPILER}/watchdog.o

#
# The default rule, which causes the library to be built.
#
all: ${COMPILER}             \
     ${COMPILER}/libdriver.a

#
# The rule to clean out all the build products.
#
clean:
	@rm -rf ${COMPILER} settings
	@rm -rf ${wildcard *~} ${wildcard *.Bak} ${wildcard *.dep}

#
# The rule to create the target directory.
#
${COMPILER}:
	@mkdir -p ${COMPILER}

#
# The rule for building the driver library from the constituent object files.
#
${COMPILER}/libdriver.a: ${OBJS}
	@if [ 'x${VERBOSE}' = x ]; \
	 then                      \
	     echo "  AR    ${@}";  \
	 fi
ifeq (${COMPILER}, ewarm)
	@touch ${@}
	@if [ 'x${VERBOSE}' != x ];      \
	 then                            \
	     echo ${AR} -o ${@} ${OBJS}; \
	 fi;                             \
	 $(AR) -o ${@} ${OBJS}
endif
ifeq (${COMPILER}, gcc)
ifeq (${OS}, Windows_NT)
	@for i in ${OBJS:.o=};                   \
	 do                                      \
	     if [ 'x${VERBOSE}' != x ];          \
	     then                                \
	         echo ${AR} -cr ${@} $${i}\*_.o; \
	     fi;                                 \
	     ${AR} -cr ${@} $${i}\*_.o;          \
	 done
else
	@for i in ${OBJS:.o=};                  \
	 do                                     \
	     if [ 'x${VERBOSE}' != x ];         \
	     then                               \
	         echo ${AR} -cr ${@} $${i}*_.o; \
	     fi;                                \
	     ${AR} -cr ${@} $${i}*_.o;          \
	 done
endif
endif
ifeq (${COMPILER}, rvmdk)
	@if [ 'x${VERBOSE}' != x ];       \
	 then                             \
	     echo ${AR} -cr ${@} ${OBJS}; \
	 fi;                              \
	 ${AR} -cr ${@} ${OBJS}
endif

#
# The rule for building the set of object files from each C source file.
#
${COMPILER}/%.o: %.c
	@if [ 'x${VERBOSE}' = x ]; \
	 then                      \
	     echo "  CC    ${<}";  \
	 fi
ifeq (${COMPILER}, ewarm)
	@if [ 'x${VERBOSE}' != x ];                                          \
	 then                                                                \
	     echo ${CC} ${CFLAGS} -D${COMPILER} -DBUILD_ALL                  \
	         -o ${@} --library_module --module_name=__lib_${<:.c=} ${<}; \
	 fi;                                                                 \
	 ${CC} ${CFLAGS} -D${COMPILER} -DBUILD_ALL                           \
	     -o ${@} --library_module --module_name=__lib_${<:.c=} ${<};     \
	 sed -e "s,\\\\,/,g" ${<:.c=.d} > ${@:.o=.d};                        \
	 rm -f ${<:.c=.d}
endif
ifeq (${COMPILER}, gcc)
	@for i in `grep ^#if\ defined\(GROUP_ ${<}`;                          \
	 do                                                                   \
	     if [ x`echo $${i} | grep defined\(GROUP_` = x ];                 \
	     then                                                             \
	         continue;                                                    \
	     fi;                                                              \
	     i=`echo $${i} | gawk -F_ '{print $$2}'`;                         \
	     i=`echo $${i} | gawk -F\) '{print $$1}'`;                        \
	     if [ 'x${VERBOSE}' != x ];                                       \
	     then                                                             \
	         echo ${CC} ${CFLAGS} -D${COMPILER} -DGROUP_$${i}             \
	             -o ${@:.o=}_$${i}_.o ${<};                               \
	     fi;                                                              \
	     ${CC} ${CFLAGS} -D${COMPILER} -DGROUP_$${i} -o ${@:.o=}_$${i}_.o \
	         ${<};                                                        \
	     if [ $${?} != 0 ];                                               \
	     then                                                             \
	         return 1;                                                    \
	     fi;                                                              \
	     sed "s/${<:.c=}_.*_\.o/${<:.c=.o}/g" ${@:.o=}_$${i}_.d >         \
	         ${@:.o=.d};                                                  \
	     rm ${@:.o=}_$${i}_.d;                                            \
	 done
	@touch ${@}
endif
ifeq (${COMPILER}, rvmdk)
	@if [ 'x${VERBOSE}' != x ];                                          \
	 then                                                                \
	     echo ${CC} ${CFLAGS} -D${COMPILER} -DBUILD_ALL --split_sections \
	         -o ${@} ${<};                                               \
	 fi;                                                                 \
	 ${CC} ${CFLAGS} -D${COMPILER} -DBUILD_ALL --split-sections          \
	     -o ${@} ${<};                                                   \
	 sed "s,\\\\,/,g" ${<:.c=.d} > ${@:.o=.d};                           \
	 rm -f ${<:.c=.d}
endif

#
# The rule for building the set of object files from each assembly source file.
#
${COMPILER}/%.o: %.S
	@if [ 'x${VERBOSE}' = x ]; \
	 then                      \
	     echo "  AS    ${<}";  \
	 fi
ifeq (${COMPILER}, ewarm)
	@if [ 'x${VERBOSE}' != x ];                                           \
	 then                                                                 \
	     echo ${CC} ${CFLAGS} -D${COMPILER} -DBUILD_ALL --preprocess=n    \
	         -o ${<:.S=.i} ${<};                                          \
	     echo ${AS} ${AFLAGS} -o ${@} ${<:.S=.i};                         \
	 fi;                                                                  \
	 ${CC} ${CFLAGS} -D${COMPILER} -DBUILD_ALL --preprocess=n             \
	     ${<:.S=.i} ${<};                                                 \
	 ${AS} ${AFLAGS} -o ${@} ${<:.S=.i};                                  \
	 sed -e "s,.*\.r79:,${@}:,g" -e "s,\\\\,/,g" ${<:.S=.d} > ${@:.o=.d}; \
	 rm -f ${<:.S=.d} ${<:.S=.i}
endif
ifeq (${COMPILER}, gcc)
	@for i in `grep ^#if\ defined\(GROUP_ ${<}`;                          \
	 do                                                                   \
	     if [ x`echo $${i} | grep defined\(GROUP_` = x ];                 \
	     then                                                             \
	         continue;                                                    \
	     fi;                                                              \
	     i=`echo $${i} | gawk -F_ '{print $$2}'`;                         \
	     i=`echo $${i} | gawk -F\) '{print $$1}'`;                        \
	     if [ 'x${VERBOSE}' != x ];                                       \
	     then                                                             \
	         echo ${CC} ${AFLAGS} -D${COMPILER} -DGROUP_$${i}             \
	             -o ${@:.o=}_$${i}_.o -c ${<};                            \
	     fi;                                                              \
	     ${CC} ${AFLAGS} -D${COMPILER} -DGROUP_$${i} -o ${@:.o=}_$${i}_.o \
	         -c ${<};                                                     \
	     if [ $${?} != 0 ];                                               \
	     then                                                             \
	         return 1;                                                    \
	     fi;                                                              \
	     sed "s/${<:.S=}_.*_\.o/${<:.S=.o}/g" ${@:.o=}_$${i}_.d >         \
	         ${@:.o=.d};                                                  \
	     rm ${@:.o=}_$${i}_.d;                                            \
	 done
	@touch ${@}
endif
ifeq (${COMPILER}, rvmdk)
	@if [ 'x${VERBOSE}' != x ];                                          \
	 then                                                                \
	     echo ${CC} ${AFLAGS} -D${COMPILER} -DBUILD_ALL -o ${@} -c ${<}; \
	 fi;                                                                 \
	 ${CC} ${AFLAGS} -D${COMPILER} -DBUILD_ALL -E ${<} > ${@:.o=.S};     \
	 ${CC} ${AFLAGS} -o ${@} -c ${@:.o=.S};                              \
	 rm ${@:.o=.S};                                                      \
	 ${CC} ${AFLAGS} -D${COMPILER} -DBUILD_ALL --md -E ${<};             \
	 sed 's,<stdout>,${@},g' ${<:.S=.d} > ${@:.o=.d};                    \
	 rm -f ${<:.S=.d}
endif

#
# Include the automatically generated dependency files.
#
-include ${wildcard ${COMPILER}/*.d} __dummy__
